const { firstLetterToUpperCase } = require('../../util/core');
module.exports = ({ Router, logger }) => {
    const router = new Router();
    const RestController = require('../../controllers/rest');

    router.prefix('/rest/:modelName');

    router.param('modelName', async (modelName, ctx, next) => {
        modelName = firstLetterToUpperCase(modelName);
        ctx.modelName = modelName;
        await next();
    })

    router.post('/add', async (ctx, next) => {
        await RestController.addController(ctx);
        await next();
    })

    router.delete('/del', async (ctx, next) => {
        await RestController.delController(ctx);
        await next();
    })

    router.delete('/softDel', async (ctx, next) => {
        await RestController.softDelController(ctx);
        await next();
    })

    router.put('/restore', async (ctx, next) => {
        await RestController.restoreController(ctx);
        await next();
    })

    router.put('/update', async (ctx, next) => {
        await RestController.updateController(ctx);
        await next();
    })

    router.get('/getById/:id', async (ctx, next) => {
        await RestController.getByIdController(ctx);
        await next();
    })

    router.get('/getByPage/:page/:limit', async (ctx, next) => {
        await RestController.getByPageController(ctx);
        await next();
    })

    router.get('/getAll', async (ctx, next) => {
        await RestController.getAllController(ctx);
        await next();
    })


    return router;
}